from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
from django.core.urlresolvers import reverse
from web.settings import BASE_DIR
import os

# 后台首页
def index(request):
    
    return render(request,'myadmin/index.html')



# 封装函数进行文件上传
def uploads(myfile):
    import time
    
    # myfile.name  2.jpg  jpg
    filename = str(time.time())+"."+myfile.name.split('.').pop()
    destination = open(BASE_DIR+"/static/pics/"+filename,"wb+")
    for chunk in myfile.chunks():      # 分块写入文件  
        destination.write(chunk)  
    destination.close()
        
    return "/static/pics/"+filename
